<?php
/* Single Posts Template */

/* Fetch admin options. */
global $options;
foreach ($options as $value) {
if(isset($value['id']) && isset ($value['std']))
	if (get_option( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_option( $value['id'] );}
}
get_header(); ?>
	<?php if (have_posts()) :
			while (have_posts()) : the_post(); ?>
			<div class="entry clearfix" id="post-<?php the_ID(); ?>">
                <h2><?php the_title(); ?></h2>
                <div class="entry-meta"><?php misa_attachment_meta(); ?></div>
				<div class="entry-content"><?php the_content(); ?></div>  
				<div class="footer-meta">
                	<span class="tags"><?php _e( 'Tag:', 'misa' ); ?> <?php the_tags( '', ', ', ' ' ) ?></span>
					<span><?php _e( 'Permalink:', 'misa' ); ?></span><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>" class="permalink"><?php the_title(); ?></a>                        
				</div> <!-- .footer-meta-->                 
 				<?php if ( $msa_author == 'Enable' ): ?>
            	<div class="about-author">
            		<h3 ><?php printf( __( 'About %s', 'misa' ), get_the_author() ); ?></h3>                             
                	<div class="author-avatar">
                    <?php 
						$dir = get_template_directory_uri();
						$default_avatar = $dir . '/images/default_avatar.jpg';
						echo get_avatar( get_the_author_meta( 'user_email' ), $size='64', $default = $default_avatar );
					?>
                	</div>
                	<div class="author-description">
                    	<p class="user-email"><?php  echo the_author_meta( 'user_email' ); ?></p>	    
                    	<p class="user-url"><a href="<?php echo the_author_meta ('user_url') ?>"><?php echo the_author_meta ('user_url') ?></a></p>
                    	<p class="user-description"><?php echo the_author_meta( 'description' ); ?></p>
                    	<p class="user-posts"><a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php printf( __( 'View all posts by %s &rarr;', 'misa' ), get_the_author() ); ?></a></p>
                	</div>
				</div><!-- .about author-->               
				<?php endif;?>             
			</div> <!-- .entry -->

            <div class="prev-next-posts">
                <div class="prev-post">
                <?php if (get_previous_post()) {
					_e( 'Previous Post:', 'misa'); previous_post_link( '%link' );
					} else {
					_e( 'Sorry, it is already the newest post.', 'misa' );
					}
				?>                
                </div>
                 <div class="next-post">
                <?php if (get_next_post()) {
					_e( 'Next post:', 'misa'); next_post_link( '%link' );
					} else {
					 _e( 'Sorry, it is already the earliest post.', 'misa' );
					} 
				?>                 
                 </div>   
            </div><!-- .pagination -->
            
			<?php if ( $msa_rp == 'Enable' ): misa_related_posts( $msa_rp_taxonomy, $msa_rp_style, $msa_rp_num ); endif; ?><!-- Related Posts -->

			<?php comments_template( '', true );?>                
	<?php endwhile; // end of the loop.
	else : ?>
            <h2><?php _e( 'Not Found', 'misa' ); ?></h2>
            <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'misa' ); ?></p>
	<?php endif; ?>
	</div><!-- .content -->            
	<?php
	$sidebar_opts = '';
	if ( is_page() ) {
			$page_opts = get_post_meta( $post->ID, 'page_options', true );
            $sidebar_opts = $page_opts['sidebar_opts'];
	}
	if ( ( $sidebar_opts == 'right' ) && ( !( $sidebar_opts == 'left' || $sidebar_opts == 'none' ) ) ){
		get_sidebar();
	}
	elseif ( ( $msa_sidebar == 'right' ) && ( !( $sidebar_opts == 'left' || $sidebar_opts == 'none' ) ) ) {
		get_sidebar();
	}
	?>
    </div><!-- .primary_wrap --> 
</div><!-- .primary -->     
<?php get_footer(); ?>